<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">课程卡订单</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                        <form class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <?php if (checkPrivilege('shop.course_order/export')): ?>
                                                <a class="j-export am-btn am-btn-success am-radius"
                                                   href="javascript:void(0);">
                                                    <i class="iconfont icon-daochu am-margin-right-xs"></i>导出记录
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <select name="shop_id"
                                                data-am-selected="{searchBox: 1, btnSize: 'sm', placeholder: '所属门店', maxHeight: 400}">
                                            <option value=""></option>
                                            <?php if (isset($shopList)): foreach ($shopList as $shop): ?>
                                                <option value="<?= $shop['shop_id'] ?>"
                                                    <?= $request->get('shop_id') == $shop['shop_id'] ? 'selected' : '' ?>>
                                                    <?= $shop['shop_name'] ?>
                                                </option>
                                            <?php endforeach; endif; ?>
                                        </select>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="nickName"
                                                   placeholder="请输入微信昵称/手机号"
                                                   value="<?= $request->get('nickName') ?>">
                                        </div>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time"
                                               class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入订单号"
                                                   value="<?= $request->get('search') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>订单编号</th>
                                <th>用户</th>
                                <th>用户头像</th>
                                <th>课程卡</th>
                                <th>所属门店</th>
                                <th>类型</th>
                                <th>总次数</th>
                                <th>剩余次数</th>
                                <th>状态</th>
                                <th>来源</th>
                                <th>订单金额</th>
                                <th>实际支付</th>
                                <th>创建时间</th>
                                <th>支付时间</th>
                                <th>生效时间</th>
                                <th>失效时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['order_no'] ?></td>
                                    <td class="am-text-middle"><?= $item['user']['nickName'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= $item['user']['avatarUrl'] ?>" title="点击查看大图" target="_blank">
                                            <img src="<?= $item['user']['avatarUrl'] ?>" width="72" height="72" alt="">
                                        </a>
                                    </td>
                                    <td class="am-text-middle"><?= $item['orderdetail']['goods_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['shop']['shop_name'] ?></td>
                                    <td class="am-text-middle"><?= $item['type']== 1?'次卡':'团课'; ?></td>
                                    <td class="am-text-middle"><?= $item['orderdetail']['nums'] ?></td>
                                    <td class="am-text-middle"><?= $item['orderdetail']['remain_nums'] ?></td>
                                    <td class="am-text-middle">
                                        <span class="am-badge am-badge-<?= $status_color[$item['orderdetail']['card_status']]; ?>">
                                           <?= $status[$item['orderdetail']['card_status']]; ?>
                                       </span>
                                    </td>
                                    <td class="am-text-middle">
                                        <span class="am-badge am-badge-<?= $item['order_source'] == 10 ? 'success':'warning'; ?>">
                                           <?= $order_source[$item['order_source']]; ?>
                                       </span>
                                    </td>
                                    <td class="am-text-middle"><?= $item['total_price']?></td>
                                    <td class="am-text-middle">
                                        <?= $item['pay_price']; ?>
                                        <?php if ($item['coupon_id'] > 0):?>
                                        33
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle"><?= $item['create_time'] ?></td>
                                    <td class="am-text-middle"><?= $item['pay_time']?date('Y-m-d H:i:s',$item['pay_time']):'' ?></td>
                                    <td class="am-text-middle"><?= $item['orderdetail']['start_time']?date('Y-m-d H:i:s',$item['orderdetail']['start_time']):'' ?></td>
                                    <td class="am-text-middle"><?= $item['orderdetail']['expire_time']?date('Y-m-d H:i:s',$item['orderdetail']['expire_time']):'' ?></td>

                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if (checkPrivilege('shop.course_order/stop') && in_array($item['orderdetail']['card_status'],[2,5])): ?>
                                                <a href="javascript:;" class="item-stop <?= $item['orderdetail']['card_status'] == 2?'tpl-table-black-operation':'tpl-table-black-operation-green'?>"
                                                   data-id="<?= $item['orderdetail']['course_order_id'] ?>" data-state="<?= $item['orderdetail']['card_status'] ?>">
                                                    <i class="am-icon-angellist"></i> <?= $item['orderdetail']['card_status'] == 2?'停用':'启用'; ?>
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                        <div class="tpl-table-black-operation">
                                            <?php if (checkPrivilege('shop.course_order/del') && in_array($item['orderdetail']['card_status'],[1])): ?>
                                                <a href="javascript:;" class="item-del tpl-table-black-operation-del"
                                                   data-id="<?= $item['orderdetail']['course_order_id'] ?>" data-state="<?= $item['orderdetail']['card_status'] ?>">
                                                    <i class="am-icon-trash"></i> 删除
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="11" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('shop.course_order/export') ?>" + '&' + $.urlEncode(data);
        });
        // 删除元素
        var url = "<?= url('shop.course_order/stop') ?>";
        $('.item-stop').click(function () {
            // 验证权限
            if (!"<?= checkPrivilege('shop.course_order/stop')?>") {
                return false;
            }
            var data = $(this).data();
            layer.confirm('确定要' + (parseInt(data.state) === 2 ? '停用' : '启用') + '该课程卡吗？'
                , {title: '友情提示'}
                , function (index) {
                    $.post("<?= url('shop.course_order/stop') ?>"
                        , {
                            course_order_id: data.id,
                            status: parseInt(data.state) === 2? 5: 2
                        }
                        , function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        });
                    layer.close(index);
                });
        });

        var del_url = "<?= url('shop.course_order/del') ?>";
        $('.item-del').click(function () {
            // 验证权限
            if (!"<?= checkPrivilege('shop.course_order/del')?>") {
                return false;
            }
            var data = $(this).data();
            layer.confirm('确定要删除此该课程卡吗？'
                , {title: '友情提示'}
                , function (index) {
                    $.post("<?= url('shop.course_order/del') ?>"
                        , {
                            course_order_id: data.id
                        }
                        , function (result) {
                            result.code === 1 ? $.show_success(result.msg, result.url)
                                : $.show_error(result.msg);
                        });
                    layer.close(index);
                });
        });

    });
</script>

